﻿using Microsoft.OpenApi.Models;
using System.Reflection;

namespace HDW_Migrate.Extensions;

/// <summary>
/// 
/// </summary>
public static class SwaggerEx
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="services"></param>
    /// <returns></returns>
    public static IServiceCollection AddSwagger(this IServiceCollection services)
    {
        services.AddSwaggerGen(options =>
        {
            options.SwaggerDoc("v1", new OpenApiInfo
            {
                Title = "海淀老 RIS 数据迁移",
                Version = "v1",
                Description = null
            });

            // 获取XML注释文件的路径
            var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
            var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);

            // 如果XML文件存在，则包含它
            if (File.Exists(xmlPath))
            {
                options.IncludeXmlComments(xmlPath);
            }
        });
        return services;
    }
}
